package class202204._21_25;

import java.util.Arrays;

public class 二维数组 {
    public static void main1(String[] args) {
        int[][] arrary = {{1,2,3,4,},{5,6,7,8}};
        int[][] arrary1 =new int[][] {{1,2,3,4,},{6,7,8}};
        int[][] arrary2 = new int[2][3];
    }
    public static void main2(String[] args) {
        int[][] arrary = {{1, 2, 3}, {5, 6, 7, 8}};
        for (int i = 0; i < 2; i++) {//i表示行
            for (int j = 0; j < 3; j++) {//j表示列
                System.out.print(arrary[i][j] + " ");
            }
            System.out.println();
        }
    }
    public static void main3(String[] args) {
        int[][] arrary = {{1, 2, 3}, {5, 6, 7, 8}};
        for (int i = 0; i < arrary.length; i++) {//i表示行
            for (int j = 0; j < arrary[i].length; j++) {//j表示列
                System.out.print(arrary[i][j] + " ");
            }
            System.out.println();
        }
    }
    public static void main4(String[] args) {
        int[][] arrary = {{1, 2, 3}, {5, 6, 7, 8}};
        System.out.println("使用for  each 打印");
        for (int[] tmp:arrary){
            for (int x:tmp){
                System.out.print(x + " ");
            }
            System.out.println();
        }
    }

    /**
     * deepToString深度打印数组
     * @param args
     */
    public static void main5(String[] args) {
        int[][] arrary = {{1, 2, 3}, {5, 6, 7, 8}};
        System.out.println("使用toString进行打印");
        System.out.println(Arrays.deepToString(arrary));
    }

    /**
     * 不规则二维数组
     * @param args
     */
    public static void main(String[] args) {
        int[][] arrary = new int[2][];
        arrary[0] = new int[2];
        arrary[1] = new int[4];
        for (int i = 0; i < arrary.length; i++) {//i表示行
            for (int j = 0; j < arrary[i].length; j++) {//j表示列
                System.out.print(arrary[i][j] + " ");
            }
            System.out.println();
        }
    }
}
